package study.concurrent.lock.controller.jdk;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.concurrent.lock.service.MutexService;
import study.concurrent.lock.support.utils.LogUtils;
import study.kit.eggs.result.Result;
import study.kit.eggs.result.Results;

@Slf4j
@RestController
@RequestMapping("/jdk")
public class SyncController {

    @Autowired
    private MutexService mutexService;

    @RequestMapping("/sync")
    public Result sync() {

        synchronized (this) {
            LogUtils.acquired("");
            mutexService.doMutex();
            log.info("释放锁");
        }
        return Results.ok();
    }
}
